home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / tmdsp / techo.c < prev    next >
C/C++ Source or Header  |  1991-10-18  |  4KB  |  184 lines

  1. /*
  2.     TECHO.C Ver 0.02 1991.08.09  by Y.Kurihara (Nif PDC01620)"
  3.         T-MENU の画面にちょっかいを出すプログラム  その3
  4.  
  5.     (1) TECHO [/] [<文字列> ... ]
  6.     (2) TECHO <X座標> <Y座標> [/] [<文字列> ... ]
  7.     (3) TECHO <X座標> <Y座標> <桁数> <行数> [/] [<文字列> ... ]
  8.  
  9.     (1) 文字列を表示する
  10.     (2) 指定位置に文字列を表示する
  11.     (3) 指定範囲に文字列を表示する
  12.  
  13.     *文字列の先頭が数字の時は、 '/' を入れることで座標と区別させる。
  14.       また、'/' の次に文字列がない時は、 標準入力を表示する。
  15.     *フォントCGの使用方法は ORICON (MIYAZAKI氏作) を参考にしました。
  16. */
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <jctype.h>
  21. #include <dos.h>
  22. #include <machine.h>
  23.  
  24. #define  X0    (2)
  25. #define  Xl    (76)
  26. #define  Y0    (7)
  27. #define  Yl    (20)
  28.  
  29. #define VRAM( offset )   ( (char far *)MK_FP( 0xc000,( offset ) ) )
  30. #define ANKCG( offset )  ( (char far *)MK_FP( 0xcb00,( offset ) ) )
  31. #define PORTpage   (0xff83)
  32. #define PORTplane  (0xff81)
  33. #define PORTank    (0xff99)
  34. #define PORTkch    (0xff94)    /* 漢字コード */
  35. #define PORTkcl    (0xff95)
  36. #define PORTkfl    (0xff96)    /* 漢字フォント */
  37. #define PORTkfr    (0xff97)
  38. #define Y1page     (16)
  39. #define MAXbuff    (256)
  40.  
  41. int  lx1,ly1,lx2,ly2,lx,ly;
  42. char buff[ MAXbuff ];
  43.  
  44. void putank( int code )
  45. {
  46.     unsigned off,add;
  47.     int n;
  48.  
  49.     if( ly < Y1page ) {
  50.         outp( PORTpage,0x00 );
  51.         off = ly * 16 * 128 + lx;
  52.     } else {
  53.         outp( PORTpage,0x10 );
  54.         off = ( ly - Y1page )* 16 * 128 + lx;
  55.     }
  56.     add = code * 16;
  57.     for( n = 16; --n >= 0;  ) {
  58.         *VRAM( off ) = ~ *ANKCG( add++ );
  59.         off += 128;
  60.     }
  61.     return;
  62. }
  63.  
  64. void putkan( unsigned code )
  65. {
  66.     int off;
  67.     int n;
  68.  
  69.     if( ly < Y1page ) {
  70.         outp( PORTpage,0x00 );
  71.         off = ly * 16 * 128 + lx;
  72.     } else {
  73.         outp( PORTpage,0x10 );
  74.         off = ( ly - Y1page )* 16 * 128 + lx;
  75.     }
  76.     code = jmstojis( code );
  77.     outp( PORTkch,code >> 8 );
  78.     outp( PORTkcl,code );
  79.     for( n = 16; --n >= 0;  ) {
  80.         *VRAM( off )     = ~ inp( PORTkfl );
  81.         *VRAM( off + 1 ) = ~ inp( PORTkfr );
  82.         off += 128;
  83.     }
  84.     return;
  85. }
  86.  
  87. void echo_char( int code )
  88. {
  89.     static int code1 = 0;
  90.  
  91.     if( code1 ) {            /* 漢字コード */
  92.         if( lx > lx2 - 1 ) {
  93.             lx = lx1;
  94.             ly++;
  95.         }
  96.         if( ly > ly2 )  return;
  97.         putkan( ( code1 << 8 )+ code );
  98.         lx  += 2;
  99.         code1 = 0;
  100.     } else if( iskanji( code ) ) {    /* 漢字コードの1文字目 */
  101.         code1 = code;
  102.     } else if( code >= ' ' ) {    /* 半角文字 */
  103.         if( lx > lx2 ) {
  104.             lx = lx1;
  105.             ly++;
  106.         }
  107.         if( ly > ly2 )  return;
  108.         putank( code );
  109.         lx++;
  110.     } else {            /* 制御コード */
  111.         if( code == '\n' ) {
  112.             lx = lx1;
  113.             ly++;
  114.         }
  115.         if( ly > ly2 )  return;
  116.     }
  117.     return;
  118. }
  119.  
  120. void echo( unsigned char *str )
  121. {
  122.     int save_page;
  123.     int save_plane;
  124.  
  125.     save_page  = inp( PORTpage );
  126.     save_plane = inp( PORTplane );
  127.     outp( PORTplane,15 );
  128.     outp( PORTank,1 );
  129.  
  130.     while( *str ) {
  131.         echo_char( *str++ );
  132.     }
  133.  
  134.     outp( PORTank,0 );
  135.     outp( PORTpage,  save_page );
  136.     outp( PORTplane, save_plane );
  137.     return;
  138. }
  139.  
  140. main( int argc,char **argv )
  141. {
  142.     int x1 = X0;
  143.     int y1 = Y0;
  144.     int x2 = Xl;
  145.     int y2 = Yl;
  146.  
  147.     argv++;
  148.     if( *argv && isdigit( **argv ) )  x1 = atoi( *argv++ );
  149.     if( *argv && isdigit( **argv ) )  y1 = atoi( *argv++ );
  150.     if( *argv && isdigit( **argv ) )  x2 = atoi( *argv++ );
  151.     if( *argv && isdigit( **argv ) )  y2 = atoi( *argv++ );
  152.  
  153.     if( x1 < 0 || y1 < 0 || x2 < 1 || y2 < 1 )  exit(1);
  154.     if( x1 >= 80 || y1 >= 30 )  exit(1);
  155.     if( ( x2 = x1 + x2 - 1 ) >= 80 )  x2 = 79;
  156.     if( ( y2 = y1 + y2 - 1 ) >= 30 )  y2 = 29;
  157.  
  158.     lx1 = x1;
  159.     lx2 = x2;
  160.     ly1 = y1;
  161.     ly2 = y2;
  162.     lx = lx1;
  163.     ly = ly1;
  164.  
  165.     if( *argv == (char *)NULL )  goto Exit;
  166.     if( **argv == '/' ) {
  167.         argv++;
  168.         if( *argv == (char *)NULL )  goto Stdin;
  169.     }
  170.     while( *argv ) {
  171.         echo( *argv++ );
  172.         echo( "\n" );
  173.         if( ly > ly2 )  break;
  174.     }
  175.     goto Exit;
  176. Stdin:
  177.     while( fgets( buff,MAXbuff,stdin ) ) {
  178.         echo( buff );
  179.         if( ly > ly2 )  break;
  180.     }
  181. Exit:
  182.     exit( 0 );
  183. }
  184.